#include <ostream>
#include <vector>

class AwesomeFlipper {
    std::vector<std::vector<bool>> appeared_num_of;
    
public:
    AwesomeFlipper(int n) : appeared_num_of(n, std::vector<bool>(6 + 1, false)) {}
    
    auto init(std::vector<int> status) {
        appeared_num_of = std::vector<std::vector<bool>>(appeared_num_of.size(), std::vector<bool>(6 + 1, false));
        for (int i = 0; i < appeared_num_of.size(); ++i) {
            appeared_num_of[i][status[i]] = true;
        }
    }

    auto flip() {
        std::vector<int> result;
        result.reserve(appeared_num_of.size());

        for (auto & dice_status : appeared_num_of) {
            for (int dice_number = 6; dice_number >= 1; --dice_number) {
                if (dice_status[dice_number] != true) {
                    dice_status[dice_number] = true;
                    // FLIP THE DICE!!
                    result.push_back(dice_number);
                    break;
                }
            }
        }

        return result;
    }
};

#include <iostream>

template<typename T>
std::ostream& operator<<(std::ostream & os, std::vector<T> const & v) {
    if (v.size() > 0) {
        auto i = v.begin();
        std::cout << *i;
        ++i;
        while (i != v.end()) {
            std::cout << " " << *i;
            ++i;
        }
    }

    return os;
}

int main() {
    constexpr int DICE_COUNT = 6;

    std::vector<int> status(DICE_COUNT);

    for (int i = 0; i < status.size(); ++i) {
        std::cin >> status[i];
    }

    AwesomeFlipper inst(DICE_COUNT);
    inst.init(status);

    int n;
    std::cin >> n;

    for (int i = 0; i < n; ++i) {
        auto result = inst.flip();
        if (i == n - 1) std::cout << result << "\n";
    }
}
